package mp.weixin.WXpublic.sendkefu;

import mp.weixin.WXpublic.BaseSendKefuMessage;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.node.JsonNodeFactory;
import org.codehaus.jackson.node.ObjectNode;

public class SKFImageEntity extends BaseSendKefuMessage {

    private String mediaId;

    public SKFImageEntity(String openId, String mediaId) {
        super(openId);
        this.mediaId = mediaId;
    }

    public String getMediaId() {
        return mediaId;
    }

    public void setMediaId(String mediaId) {
        this.mediaId = mediaId;
    }

    @Override
    public String toWeiXinKefuMessageJsonString() {
        ObjectNode jsono = new ObjectNode(JsonNodeFactory.instance);
        ObjectNode image = new ObjectNode(JsonNodeFactory.instance);
        image.put("media_id", this.getMediaId());
        jsono.put("touser", this.getToUser());
        jsono.put("msgtype", getMsgType().getType());
        jsono.put(getMsgType().getType(), image);
        if (getKfAccount() != null && !getKfAccount().equals("")) {
            ObjectNode kf = new ObjectNode(JsonNodeFactory.instance);
            kf.put("kf_account", getKfAccount());
            jsono.put("customservice", kf);
        }

        return jsono.toString();
    }

    @Override
    public BaseSendKefuMessage.SendTypeEnum getMsgType() {
        return BaseSendKefuMessage.SendTypeEnum.IMAGE;
    }

}
